home *** CD-ROM | disk | FTP | other *** search
/ Practical Algorithms for Image Analysis / Practical Algorithms for Image Analysis.iso / TARFILE.GZ / tarfile / ch_3.5 / bcd / thld.c < prev    next >
Encoding:
C/C++ Source or Header  |  1999-09-11  |  637 b   |  32 lines

  1. /*
  2.  * This program is used with permission from I. Cox.
  3.  * Please reference:
  4.  * R. A. Boie, I. Cox, Proc. IEEE 1st Int. Conf. Computer Vision,
  5.  * London, 1987, pp. 450-456.
  6.  */
  7.  
  8. #include <stdio.h>
  9. #include "edge_finder.h"
  10.  
  11. extern struct image *my_image;
  12.  
  13. int
  14. image_threshold ()
  15. {
  16.   int ix, iy, nx, ny;
  17.   int *detx, tmp;
  18.   float mad = (float) 0;        /* calculate mean absolute deviation */
  19.  
  20.   detx = my_image->idx;
  21.   nx = my_image->nx;
  22.   ny = my_image->ny;
  23.  
  24.   for (iy = 0; iy < ny; iy++) {
  25.     for (ix = 0; ix < nx; ix++) {
  26.       tmp = *detx++;
  27.       mad += abs (tmp);
  28.     }
  29.   }
  30.   return ((int) ((float) (3 * mad / nx / ny) / 0.8));
  31. }
  32.